<template>
  <div class="searchBox" ref="searchBox" winSoTop>
    <van-icon name="wap-nav" size="30px" color="#fff" />
    <div class="search">
      <span class="input_logo">G</span>
      <van-icon name="search" size="24px" color="#666" class="fonts1" />
      <input type="text" placeholder="家电返场同价11.11" />
      <!-- <van-search v-model="value" placeholder="家电返场同价11.11" /> -->
    </div>
    <p class="right_fonts" @click="$router.push('/loginPage')" v-if="!temp">
      登录
    </p>
    <van-icon
      name="manager-o"
      color="#fff"
      size="26px"
      v-if="temp"
      @click="$router.push('/myHome')"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      temp: false,
    };
  },
  methods: {
    // 监听window的滚动
    scrollto() {
      if (!this.$refs.searchBox) {
        return;
      }
      if (window.scrollY >= 180) {
        this.$refs.searchBox.classList.add("bgc");
      } else {
        this.$refs.searchBox.classList.remove("bgc");
      }
    },
  },
  created() {
    document.addEventListener("scroll", this.scrollto);
    // 判断登录状态，确定首页头部右侧图标渲染
    if (window.sessionStorage.getItem("token")) {
      this.temp = true;
    } else {
      this.temp = false;
    }
  },
};
</script>

<style lang="scss" scoped>
.searchBox {
  position: fixed;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 63px;
  padding: 0 16px;
  background: rgba(0, 0, 0, 0);
  box-sizing: border-box;
  z-index: 50;

  .search {
    display: flex;
    align-items: center;
    width: 280px;
    height: 33px;
    background-color: #fff;
    padding: 5px 0;
    border-radius: 26px;
    box-sizing: border-box;

    .input_logo {
      padding: 0 8px;
      margin-right: 8px;
      color: #f63515;
      font-size: 21px;
      font-weight: 700;
      border-right: 1px solid #666;
    }

    .fonts1 {
      margin-right: 5px;
    }

    input {
      height: 24px;
      width: 60%;
      border: none !important;
      border-color: #fff;
      font-size: 15px;
      line-height: 24px;
      background-color: #fff;
    }
  }

  .right_fonts {
    font-size: 17px;
    color: #fff;
  }
}
.bgc {
  background-color: #f63515;
}
</style>
